package com.hfuu.controller.schedule;

import com.hfuu.model.ResponseEntity;
import com.hfuu.model.ResponseEntityBuilder;
import com.hfuu.service.schedule.ScheduleService;
import com.hfuu.service.schedule.request.UpdateUserScheduleRequest;
import com.hfuu.service.schedule.request.UserScheduleRequest;
import com.hfuu.service.schedule.response.UserScheduleResponse;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.core.MediaType;
import java.util.List;

/**
 * Author: admin
 * Date: 2018/4/17
 * time: 下午4:39
 */
@RestController
@RequestMapping("/api/schedule")
public class ScheduleController {

    @Autowired
    private ScheduleService scheduleService;

    @ApiOperation("通过第几周和用户Id，获得空闲时间表")
    @RequestMapping(value = "/getUserScheduleById", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON)
    @ResponseBody
    public ResponseEntity<List<UserScheduleResponse>> getUserScheduleById(@RequestBody UserScheduleRequest request)
            throws Exception{
        return ResponseEntityBuilder.success(scheduleService.getUserScheduleById(request));
    }


    @ApiOperation("通过第几周和用户Id，更新一个时间段的时间表")
    @RequestMapping(value = "/updateUserScheduleById", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON)
    @ResponseBody
    public ResponseEntity<Integer> updateUserScheduleById(@RequestBody UpdateUserScheduleRequest request)
            throws Exception{
        return ResponseEntityBuilder.success(scheduleService.updateUserScheduleById(request));
    }

    @ApiOperation("以用户为单位同步个性时间表，到空闲用户表中")
    @RequestMapping(value = "/synchronizeScheduleById", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON)
    @ResponseBody
    public ResponseEntity<Integer> synchronizeScheduleById(@RequestBody UpdateUserScheduleRequest request)
            throws Exception{
        return ResponseEntityBuilder.success(scheduleService.synchronizeScheduleById(request));
    }

    @ApiOperation("通过第几周和组织ID，获得空闲用户表")
    @RequestMapping(value = "/getUserFreeScheduleById", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON)
    @ResponseBody
    public ResponseEntity<List<UserScheduleResponse>> getUserFreeScheduleById(@RequestBody UserScheduleRequest request)
            throws Exception{
        return ResponseEntityBuilder.success(scheduleService.getUserFreeScheduleById(request));
    }
}
